<?php

class Settings_Form_SettingFanPage extends YouNet_Form {

    protected  $_id_campaign = NULL ;
    private $_FOLDER_IMAGE_BANNER = NULL;
    private $_FOLDER_IMAGE_BACKGROUND = NULL;
    private $_FOLDER_IMAGE_WELCOME = NULL;
    private $_FOLDER_IMAGE_SHARE = NULL;
    
    private $_FOLDER_THUMBNAIL_BANNER = NULL;
    private $_FOLDER_THUMBNAIL_BACKGROUND = NULL;
    private $_FOLDER_THUMBNAIL_WELCOME = NULL;
    
    private $_default_thumbnail_banner = NULL;
    private $_default_thumbnail_background = NULL;
    private $_default_thumbnail_welcome = NULL;
    private $_default_thumbnail_share = NULL;
    
     protected $_button_decorators = array(
		'ViewHelper',
		'Tooltip',
        'DtDdWrapper'
    );
    
    
    function __construct($id_campaign, array $options) {
        $this->_id_campaign = $id_campaign ;
                
        $this->setFolderImageBanner($options['folder_banner']);
        $this->setFolderImageBackground($options['folder_background']);
        $this->setFolderImageWelcome($options['folder_welcome']);
        $this->setFolderImageShare($options['folder_share']);
        
        $this->setFolderThumbnailBanner($options['folder_thumbnail_banner']);
        $this->setFolderThumbnailBackground($options['folder_thumbnail_background']);
        $this->setFolderThumbnailWelcome($options['folder_thumbnail_welcome']);
        
        
        if (isset($options['default_thumnail_share']))
        {
            $this->setDefaultThumbnailShare($options['default_thumnail_share']);
        }
        if (isset($options['default_thumnail_welcome']))
        {
            $this->setDefaultThumbnailWelcome($options['default_thumnail_welcome']);
        }
        
        parent::__construct();
    }

    public function init() {
        /* Form */
        $this->setName('sharing_form');
                     
        //add hidden field id_campaign
        $this->addElement('hidden','id_campaign',array(
            'value' => $this->_id_campaign
        ));
        $this->id_campaign->removeDecorator('Label');
        
        //add subform FangateSetting
        $fangateSubForm = new YouNet_Form_SubForm_FangateSetting(array(
            'folder_welcome'     => $this->_FOLDER_IMAGE_WELCOME,
            'folder_thumbnail_welcome'     => $this->_FOLDER_THUMBNAIL_WELCOME,
            'default_thumnail_welcome' => $this->_default_thumbnail_welcome
        ));
        $fangateSubForm->setLabel($this->getTranslator()->translate('HEADER_FANGATE_SETTINGS') .' <hr>'); 
        $this->addSubForm($fangateSubForm,'fangate_content');
        
        //add subform ThemeSetting
        $themeSubForm = new YouNet_Form_SubForm_ThemeSetting(array(
            'folder_background' => $this->_FOLDER_IMAGE_BACKGROUND,
            'folder_banner'     => $this->_FOLDER_IMAGE_BANNER,
            'folder_thumbnail_background' => $this->_FOLDER_THUMBNAIL_BACKGROUND,
            'folder_thumbnail_banner'     => $this->_FOLDER_THUMBNAIL_BANNER,
            'default_thumnail_background' => $this->_default_thumbnail_background,
            'default_thumnail_banner' => $this->_default_thumbnail_banner
        ));
        //$themeSubForm->setLabel('<span>Theme content settings</span><span> <hr></span>'); 
        $themeSubForm->setLabel($this->getTranslator()->translate('HEADER_THEME_SETTINGS') .' <hr>'); 
        $this->addSubForm($themeSubForm,'theme_content');
        
        // add subform ShareSetting
        $shareSubForm = new YouNet_Form_SubForm_ShareSetting(array(
            'folder_share' => $this->_FOLDER_IMAGE_SHARE,
            'default_thumnail_share' => $this->_default_thumbnail_share
        ));
        
        //$shareSubForm->setLabel('Share content settings <hr>'); 
        $shareSubForm->setLabel($this->getTranslator()->translate('HEADER_SHARE_SETTINGS') .' <hr>'); 
        $this->addSubForm($shareSubForm,'share_content');
        
        //add subform BasicSetting
        $basicSubForm = new YouNet_Form_SubForm_BasicSetting();
        //$basicSubForm->setLabel('General content settings <hr>'); 
        $basicSubForm->setLabel($this->getTranslator()->translate('HEADER_GENERAL_SETTINGS') .' <hr>'); 
        $this->addSubForm($basicSubForm,'basic_content');
        
        // Submit element
        $this->addElement('submit', 'submit', array(
            'label' => 'Submit'
            ,'decorators' => $this->_button_decorators
        ));
               
    }
    
    //set default image banner 
    public function setDefaultThumbnailBanner($image)
    {
        $this->$_default_thumbnail_banner = $image;
    }
     //set default image banner 
    public function setDefaultThumbnailBackground($image)
    {
        $this->_default_thumbnail_background = $image;
    }
     //set default image share 
    public function setDefaultThumbnailShare($image)
    {
        $this->_default_thumbnail_share = $image;
    }
     //set default image fangate 
    public function setDefaultThumbnailWelcome($image)
    {
        $this->_default_thumbnail_welcome = $image;
    }
    
    
    //set folder image banner
    public function setFolderImageBanner($folder)
    {
        $this->_FOLDER_IMAGE_BANNER = $folder;
    }
    
    //set folder image banner
    public function setFolderImageBackground($folder)
    {
         $this->_FOLDER_IMAGE_BACKGROUND= $folder;
    }
    
    //set folder image welcome
    public function setFolderImageWelcome($folder)
    {
         $this->_FOLDER_IMAGE_WELCOME = $folder;
    }
    
    //set folder image share
    public function setFolderImageShare($folder)
    {
         $this->_FOLDER_IMAGE_SHARE = $folder;
    }
    
    //set folder image banner
    public function setFolderThumbnailBanner($folder)
    {
        $this->_FOLDER_THUMBNAIL_BANNER = $folder;
    }
    
    //set folder image banner
    public function setFolderThumbnailBackground($folder)
    {
         $this->_FOLDER_THUMBNAIL_BACKGROUND= $folder;
    }
    
    //set folder image welcome
    public function setFolderThumbnailWelcome($folder)
    {
         $this->_FOLDER_THUMBNAIL_WELCOME = $folder;
    }
    
    //get folder image share
    public function getFolderImageShare()
    {
         return $this->_FOLDER_IMAGE_SHARE ;
    }
    
    //get folder image banner
    public function getFolderImageBanner()
    {
        return $this->_FOLDER_IMAGE_BANNER ;
    }
    
    //get folder image background
    public function getFolderImageBackground()
    {
         return $this->_FOLDER_IMAGE_BACKGROUND ;
    }
    
    
    
    //get folder image welcome
    public function getFolerImageWelcome()
    {
         return $this->_FOLDER_IMAGE_WELCOME ;
    }
    
    /**
     * 
     * @param type $text : text label
     */
    public function seLabelSubmit($text)
    {
        $this->submit->setLabel($text);
    }
    
    /**
     * 
     * @param type $text :name of class
     */
    public function setClassSubmit($text)
    {
        $this->submit->setAttrib("class",$text);
    }
    
    public function setDefaultImageShare($image)
    {
        $this->share_content->setDefaultImageShare($image);
    }
    
    public function getImage($name,$name_subform,$size_thumnail = null) {
        return $this->$name_subform->_getImage($name,$size_thumnail);
        //return $this->_getImageNameAndReceive($name,$folder_upload,$folder_thumnail,$size_thumnail);
    }
    public function getImages($size_thumnail = null) {
        
        return 
            array_merge(
                $this->share_content->_getImage(null),
                $this->theme_content->_getImage($size_thumnail),
                $this->fangate_content->_getImage($size_thumnail)
            );
    }
    
    function mergDataPost($post_values)
    {
        $arr_share = $post_values["share_content"];
        $arr_basic = $post_values["basic_content"];
        $arr_theme = $post_values["theme_content"];
        $arr_fangate = $post_values["fangate_content"];
        
//        $arr_fangate = array(
//            "fangate_required"=>$post_values["fangate_content"]["fangate_required"][0],
//            "fangate_image" => $post_values["fangate_content"]["fangate_image"]);
//        
        $arr_images = array();//$this->getImages(160);
        
        
        return array_merge($arr_share,$arr_basic,$arr_theme,$arr_fangate,$arr_images);

    }
    
    function _addElements($ele,$name_subform)
    {
        $this->$name_subform->addElement($ele);
    }
    function _removeElement($arr_name_ele)
    {
        foreach ($arr_name_ele as $key=>$value)
        {
            $this->removeElement($key);
        }
    }
}